package com.justnow.offer;

import java.util.Scanner;
import java.util.Stack;

/**
 * @author justnow
 * Created on 2020-09-12
 * Description
 */
public class Yfd02 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        scanner.nextLine();
        for (int i = 0; i < T; i++) {
            String str = scanner.nextLine();
            System.out.println(charge(str));
        }
    }

    public static String charge(String str) {
        if (str.charAt(0) != '(' || str.charAt(str.length() - 1) != ')')
            return "invalid";
        if (!str.contains("+") ) {
            return "invalid";
        }
        Stack<Character> stack = new Stack<>();
        char[] chars = str.toCharArray();

        for (char aChar : chars) {
            if (aChar == ')') {
                Character pop2 = stack.pop();
                Character pop1 = stack.pop();
                Character signal = stack.pop();
                if (signal == '+') {
                }
            }
            stack.add(aChar);
        }
        return "0";

    }
}
